#include "cuDevice.h"

void cuDevice(cudaDeviceProp & device_properties)
{
  cudaError_t cuda_error;

  memset( &device_properties, 0, sizeof(device_properties) );

  int count = 0;

  CUDA_CHECK_ERROR( cudaGetDeviceCount( &count ) );

  if (count == 0)
    return;

#ifdef _DEBUG
  fprintf(stdout, "Device Count %d \n", count);
#endif

  CUDA_CHECK_ERROR( cudaGetDeviceProperties( &device_properties, 0 ) );

#ifdef _DEBUG
  const int iKb = 1024;
  const int iMb = 1024 * iKb;

  fprintf( stdout, "\t Name %s \n",                             device_properties.name                   );
  fprintf( stdout, "\t Total global memory %d MB \n",           device_properties.totalGlobalMem / iMb   );  
  fprintf( stdout, "\t Total const  memory %d KB \n",           device_properties.totalConstMem / iKb    );  
  fprintf( stdout, "\t Total shared memory per block %d KB \n", device_properties.sharedMemPerBlock / iKb);
  fprintf( stdout, "\t Total register per block %d Kb \n",      device_properties.regsPerBlock / iKb     );
  fprintf( stdout, "\t Warp size %d \n",                        device_properties.warpSize               );
  fprintf( stdout, "\t Maximum allowed memory pitch %d\n",      device_properties.memPitch               );
  fprintf( stdout, "\t Max threads per bloc %d \n",             device_properties.maxThreadsPerBlock     );

  int threads[3] = { device_properties.maxThreadsDim[0], 
                     device_properties.maxThreadsDim[1],
                     device_properties.maxThreadsDim[2] };

  fprintf( stdout, "\t Max threads per block (%d, %d, %d) \n", threads[0], threads[1], threads[2] );

  int blocks[3] = { device_properties.maxGridSize[0], 
                    device_properties.maxGridSize[1], 
                    device_properties.maxGridSize[2] };

  fprintf( stdout, "\t Max blocks per grid (%d, %d, %d) \n",   blocks[0], blocks[1], blocks[2]    );

  int version[2] = { device_properties.major, 
                     device_properties.minor };

  fprintf( stdout, "\t Compute Caps %d.%d \n",      version[0], version[1]                    );
  fprintf( stdout, "\t Clock Rate %d Mhz \n",       device_properties.clockRate / iKb         ); // clock rate is in Khz already
  fprintf( stdout, "\t Texture Alignment %d \n",    device_properties.textureAlignment        );
  fprintf( stdout, "\t Device Overlap %d \n",       device_properties.deviceOverlap           );
  fprintf( stdout, "\t Multiprocessor count %d \n", device_properties.multiProcessorCount     );
  fprintf( stdout, "\t Kernel timeout %d \n",       device_properties.kernelExecTimeoutEnabled);
#endif

}